import com.example.qzword.demos.model.Student;
import com.example.qzword.demos.service.impl.StudentRepository;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Optional;

@Service
public class StudentService {
    private final StudentRepository studentRepository;

    public StudentService(StudentRepository studentRepository) {
        this.studentRepository = studentRepository;
    }

    // 查询所有学生
    public List<Student> findAll() {
        return studentRepository.findAll();
    }

    // 根据id查询学生
    public Optional<Student> findById(Long id) {
        return studentRepository.findById(id);
    }

    // 添加学生
    public Student save(Student student) {
        return studentRepository.save(student);
    }

    // 修改学生
    public Student update(Student student) {
        return studentRepository.save(student);
    }

    // 删除学生
    public void deleteById(Long id) {
        studentRepository.deleteById(id);
    }
}